package com.chapter5.string;

import java.util.Arrays;

import org.junit.Test;

import com.util.Constants;
import com.util.In;

public class TestString {

	private String[] s = { "dab", "cab", "fad", "bad", "dad", "ebb", "ace",
			"add", "fed", "bed", "fee", "bee" };

	@Test
	public void test1() {
		// String a="";
		// a.concat("bbb");
		// StringBuilder sb=new StringBuilder();
		// StringBuffer s=null;
		
		String a="abdafdsfdsf";
		int index=a.indexOf("aa");
	}

	@Test
	public void test2() {
		SuffixArray.format("abcdefg");
	}

	@Test
	public void test3() {
		System.out.println(PrefixCommon.getLength("prefectch", "prefix"));

		Arrays.sort(new String[10]);
	}

	@Test
	public void testKeyIndexCount() {
		char[] c = { 'd', 'a', 'c', 'f', 'f', 'b', 'd', 'b', 'f', 'b', 'e', 'a' };
		// System.out.println(Alphabet.LOWERCASE.R());
		KeyIndexCount.sort(c);
		// Arrays.sort(c);//时间复杂度NlgN
		System.out.println(Arrays.toString(c));
	}

	@Test
	public void testLSD() {
		LSD.sort(s, 3);
		System.out.println(Arrays.toString(s));
	}

	@Test
	public void testMSD() {
		In in = new In(Constants.dirPath + "shells.txt");
		String[] a = in.readAllStrings();
		MSD.sort(a);
		System.out.println(isSorted(a));
		System.out.println(Arrays.toString(a));
	}

	@Test
	public void test3Way() {
		In in = new In(Constants.dirPath + "shells.txt");
		String[] a = in.readAllStrings();
		ThreeWayRadixQuickSort.sort(a);
		System.out.println(isSorted(a));
		System.out.println(Arrays.toString(a));
	}

	private boolean isSorted(String[] s) {
		for (int i = 0; i < s.length - 1; i++) {
			if (s[i].compareTo(s[i + 1]) > 0)
				return false;
		}
		return true;
	}

	@Test
	public void testLRS() {
		// String s="aacaagtttacaagc";
		In in = new In(Constants.dir + "mobydick.txt");
		String s = in.readAll();
		// System.out.println(s);
		System.out.println(LRS.lrs(s));
	}

	@Test
	public void testStringST() {
		TrieST<Integer> st = new TrieST<Integer>();
		// new TST<Integer>();
		st.put("jack", 0);
		st.put("andy", 1);
		st.put("tom", 2);
		st.put("jim", 3);
		st.put("jerry", 4);
		st.put("tony", 5);
		// st.delete("andy");
		// System.out.println(st.get("jack"));
		// System.out.println(st.get("andy"));
		// System.out.println(st.get("tom"));
		// st.put("aaa", 3);
		// System.out.println(st.get("aaa"));

		// for(String s:st.keys()){
		// System.out.println(s);
		// }
		// Iterable<String> p=st.keysWithPrefix("je");
		// for(String pre:p){
		// System.out.println(pre);
		// }

		System.out.println(st.longestPrefixOf("jerr"));
	}
	
	@Test
	public void testBF(){
		//brute force暴力算法
		System.out.println(BruteForce.search("jack","jacknamesimple"));
		
	}
	
}
